<%

  Public Function FileExist(ByVal FilePath)
    Dim fs
    Set fs = Server.CreateObject("Scripting.FileSystemObject")
    FilePath = Server.MapPath(FilePath)
    If fs.FileExists(FilePath) Then
      FileExist = True
    Else
      FileExist = False
    End If
  End Function

  Public Sub SaveText(Text, FilePath, CharsetType)
    Dim ados
    If Len(FilePath) = 0 Then Exit Sub
    FilePath = Server.MapPath(FilePath)
    Set ados = Server.CreateObject("Adodb.Stream")
    ados.Charset = CharsetType 'utf-8，Unicode。
    ados.Type = 2
    ados.Open
    ados.WriteText text
    ados.Position = 0
    ados.SaveToFile FilePath, 2 '一次性读取所有文本，可以设置读取文本数量，自己查询ADODB.STREAM对象
    ados.Close
    Set ados = Nothing
  End Sub
  
  Public Function ReadText(FilePath, CharsetType)
    Dim ados
    If Len(FilePath) = 0 Then
      ReadText = ""
      Exit Function
    End If

    If FileExist(FilePath) = false Then
      ReadText = ""
      Exit Function
    End If

    FilePath = Server.MapPath(FilePath)

    Set ados =Server.CreateObject("adodb.stream")
    ados.Charset = CharsetType 'utf-8，Unicode。
    ados.Type = 2
    ados.Open
    ados.LoadFromFile FilePath
    ados.Position = 0
    ReadText = ados.ReadText '一次性读取所有文本，可以设置读取文本数量，自己查询ADODB.STREAM对象
    ados.Close
    Set ados = Nothing
  End Function
%>
